package cn.scw.project.goods.controller;

import cn.scw.common.constant.SysConsts;
import cn.scw.framework.aspectj.lang.annotation.Log;
import cn.scw.framework.aspectj.lang.enums.BusinessType;
import cn.scw.framework.web.controller.BaseController;
import cn.scw.framework.web.domain.AjaxResult;
import cn.scw.framework.web.page.TableDataInfo;
import cn.scw.project.goods.domain.netework.bean.GCartAddReq;
import cn.scw.project.goods.domain.vo.GCartVo;
import cn.scw.project.goods.service.IGCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购物车Controller
 *
 * @author api
 * @date 2020-05-20
 */
@Api(tags = "购物车")
@RestController
@RequestMapping(SysConsts.CONTEXT_PATH+"/goods/cart")
public class GCartController extends BaseController {
    @Autowired
    private IGCartService gCartService;

    @ApiOperation("查询购物车列表")
    //@PreAuthorize("@ss.hasPermi('goods:cart:list')")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<GCartVo> list = gCartService.selectGCartList();
        return getDataTable(list);
    }

    @ApiOperation("获取购物车详细信息")
    //@PreAuthorize("@ss.hasPermi('goods:cart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(gCartService.selectGCartById(id));
    }

    @ApiOperation("新增购物车")
    //@PreAuthorize("@ss.hasPermi('goods:cart:add')")
    @Log(title = "购物车", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(GCartAddReq req) {
        return toAjax(gCartService.insertGCart(req));
    }

    @ApiOperation("修改购物车")
    //@PreAuthorize("@ss.hasPermi('goods:cart:edit')")
    @Log(title = "购物车", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(GCartAddReq req) {
        return toAjax(gCartService.updateGCart(req));
    }

    @ApiOperation("删除购物车")
    //@PreAuthorize("@ss.hasPermi('goods:cart:remove')")
    @Log(title = "购物车", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(gCartService.deleteGCartByIds(ids));
    }
}
